<?
/* 	
	GIOV Solution - Keep IT Simple
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}
		
		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */		
var master_lesson_plan_DataStore;
var master_lesson_plan_ColumnModel;
var master_lesson_plan_ListEditorGrid;
var master_lesson_plan_createForm;
var master_lesson_plan_createWindow;
var master_lesson_plan_searchForm;
var master_lesson_plan_searchWindow;
var master_lesson_plan_SelectedRow;
var master_lesson_plan_ContextMenu;
//for detail data
var detail_lesson_plan_DataStore;
var detail_lesson_plan_ListEditorGrid;
var detail_lesson_plan_ColumnModel;
var detail_lesson_plan_proxy;
var detail_lesson_plan_writer;
var detail_lesson_plan_reader;
var editor_detail_lesson_plan;

//declare konstant
var lessonplan_post2db = '';
var msg = '';
var lessonplan_pageS=15;

/* declare variable here for Field*/
var lesplan_idField;
var lesplan_teacherField;
var anam_tanggalField;
var lesplan_classField;
var anam_pengobatanField;
var anam_perawatanField;
var anam_terapiField;
var lesplan_themeField;
var lesplan_subThemeField;
var lesplan_noteField;
var anam_obatalergiField;
var anam_efekobatalergiField;
var anam_hamilField;
var anam_kbField;
var anam_harapanField;
var lesplan_idSearchField;
var lesplan_teacherSearchField;
var lesplan_tanggalSearchField;
var lesplan_classSearchField;
var anam_pengobatanSearchField;
var anam_perawatanSearchField;
var anam_terapiSearchField;
var anam_alergiSearchField;
var anam_obatalergiSearchField;
var anam_efekobatalergiSearchField;
var anam_hamilSearchField;
var anam_kbSearchField;
var anam_harapanSearchField;

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */
  
  	/* Function for Saving inLine Editing */
	function master_lesson_plan_update(oGrid_event){
		var lesplan_id_update_pk="";
		var anam_cust_update=null;
		var anam_tanggal_update_date="";
		var anam_petugas_update=null;
		var anam_pengobatan_update=null;
		var anam_perawatan_update=null;
		var anam_terapi_update=null;
		var anam_alergi_update=null;
		var anam_obatalergi_update=null;
		var anam_efekobatalergi_update=null;
		var anam_hamil_update=null;
		var anam_kb_update=null;
		var anam_harapan_update=null;

		lesplan_id_update_pk = oGrid_event.record.data.lesplan_id;
		if(oGrid_event.record.data.anam_cust!== null){anam_cust_update = oGrid_event.record.data.anam_cust;}
	 	if(oGrid_event.record.data.anam_tanggal!== ""){anam_tanggal_update_date =oGrid_event.record.data.anam_tanggal.format('Y-m-d');}
		if(oGrid_event.record.data.anam_petugas!== null){anam_petugas_update = oGrid_event.record.data.anam_petugas;}
		if(oGrid_event.record.data.anam_pengobatan!== null){anam_pengobatan_update = oGrid_event.record.data.anam_pengobatan;}
		if(oGrid_event.record.data.anam_perawatan!== null){anam_perawatan_update = oGrid_event.record.data.anam_perawatan;}
		if(oGrid_event.record.data.anam_terapi!== null){anam_terapi_update = oGrid_event.record.data.anam_terapi;}
		if(oGrid_event.record.data.anam_alergi!== null){anam_alergi_update = oGrid_event.record.data.anam_alergi;}
		if(oGrid_event.record.data.anam_obatalergi!== null){anam_obatalergi_update = oGrid_event.record.data.anam_obatalergi;}
		if(oGrid_event.record.data.anam_efekobatalergi!== null){anam_efekobatalergi_update = oGrid_event.record.data.anam_efekobatalergi;}
		if(oGrid_event.record.data.anam_hamil!== null){anam_hamil_update = oGrid_event.record.data.anam_hamil;}
		if(oGrid_event.record.data.anam_kb!== null){anam_kb_update = oGrid_event.record.data.anam_kb;}
		if(oGrid_event.record.data.anam_harapan!== null){anam_harapan_update = oGrid_event.record.data.anam_harapan;}

		Ext.Ajax.request({  
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_master_lesson_plan&m=get_action',
			params: {
				task: "UPDATE",
				lesplan_id	: lesplan_id_update_pk, 
				anam_cust	:anam_cust_update,  
				anam_tanggal	: anam_tanggal_update_date, 
				anam_petugas	:anam_petugas_update,  
				anam_pengobatan	:anam_pengobatan_update,  
				anam_perawatan	:anam_perawatan_update,  
				anam_terapi	:anam_terapi_update,  
				anam_alergi	:anam_alergi_update,  
				anam_obatalergi	:anam_obatalergi_update,  
				anam_efekobatalergi	:anam_efekobatalergi_update,  
				anam_hamil	:anam_hamil_update,  
				anam_kb	:anam_kb_update,  
				anam_harapan	:anam_harapan_update  
			}, 
			success: function(response){							
				var result=eval(response.responseText);
				switch(result){
					case 1:
						master_lesson_plan_DataStore.commitChanges();
						master_lesson_plan_DataStore.reload();
						break;
					default:
						Ext.MessageBox.show({
						   title: 'Warning',
						   msg: 'Lesson Plan Data cannot be saved!',
						   buttons: Ext.MessageBox.OK,
						   animEl: 'save',
						   icon: Ext.MessageBox.WARNING
						});
						break;
				}
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.show({
				   title: 'Error',
				   msg: 'Cannot connect to Server!',
				   buttons: Ext.MessageBox.OK,
				   animEl: 'database',
				   icon: Ext.MessageBox.ERROR
				});	
			}									    
		});   
	}
  	/* End of Function */
  
  	/* Function for add data, open window create form */
	function master_lesson_plan_create(){
	
		if(is_master_lesson_plan_valid()){	
		var lesplan_id_create_pk=null; 
		var lesplan_code_create=null; 
		var lesplan_teacher_create=null; 
		var lesplan_class_create=null; 
		var lesplan_theme_create=null; 
		var lesplan_subtheme_create=null; 
		var lesplan_note_create=null; 
		var lesplan_month_create = null;
		var lesplan_year_create = null;
		var lesplan_capacity_create = null;

		if(lesplan_idField.getValue()!== null){lesplan_id_create_pk = lesplan_idField.getValue();}else{lesplan_id_create_pk=get_pk_id();} 
		if(lesplan_codeField.getValue()!== null){lesplan_code_create = lesplan_codeField.getValue();} 
		if(lesplan_teacherField.getValue()!== null){lesplan_teacher_create = lesplan_teacherField.getValue();} 
		if(lesplan_classField.getValue()!== null){lesplan_class_create = lesplan_classField.getValue();} 
		if(lesplan_themeField.getValue()!== null){lesplan_theme_create = lesplan_themeField.getValue();} 
		if(lesplan_subThemeField.getValue()!== null){lesplan_subtheme_create = lesplan_subThemeField.getValue();} 
		if(lesplan_noteField.getValue()!== null){lesplan_note_create = lesplan_noteField.getValue();} 
		if(lesplan_monthField.getValue()!== null){lesplan_month_create = lesplan_monthField.getValue();} 
		if(lesplan_yearField.getValue()!== null){lesplan_year_create = lesplan_yearField.getValue();} 
		if(lesplan_capacityField.getValue()!== null){lesplan_capacity_create = lesplan_capacityField.getValue();} 

		// Penambahan Detail Lesson Plan
		var dplan_id = [];
        var dplan_master = [];
        var dplan_time_start = [];
        var dplan_time_end = [];
        var dplan_daily_schedule = [];
        var dplan_week1_1 = [];
        var dplan_week1_2 = [];
        var dplan_week2_1 = [];
        var dplan_week2_2 = [];
        var dplan_week3_1 = [];
        var dplan_week3_2 = [];
        var dplan_week4_1 = [];
        var dplan_week4_2 = [];
		
        if(detail_lesson_plan_DataStoree.getCount()>0){
            for(i=0; i<detail_lesson_plan_DataStoree.getCount();i++){
                if(detail_lesson_plan_DataStoree.getAt(i).data.dplan_time_start!==""
				   && detail_lesson_plan_DataStoree.getAt(i).data.dplan_time_end!==""){

                  	dplan_id.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_id);
					dplan_time_start.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_time_start);
                   	dplan_time_end.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_time_end);
					dplan_daily_schedule.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_daily_schedule);
					dplan_week1_1.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week1_1);
					dplan_week1_2.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week1_2);
					dplan_week2_1.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week2_1);
					dplan_week2_2.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week2_2);
					dplan_week3_1.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week3_1);
					dplan_week3_2.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week3_2);
					dplan_week4_1.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week4_1);
					dplan_week4_2.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week4_2);
                }
            }
			
			var encoded_array_dplan_id = Ext.encode(dplan_id);
			var encoded_array_dplan_time_start = Ext.encode(dplan_time_start);
			var encoded_array_dplan_time_end = Ext.encode(dplan_time_end);
			var encoded_array_dplan_daily_schedule = Ext.encode(dplan_daily_schedule);
			var encoded_array_dplan_week1_1 = Ext.encode(dplan_week1_1);
			var encoded_array_dplan_week1_2 = Ext.encode(dplan_week1_2);
			var encoded_array_dplan_week2_1 = Ext.encode(dplan_week2_1);
			var encoded_array_dplan_week2_2 = Ext.encode(dplan_week2_2);
			var encoded_array_dplan_week3_1 = Ext.encode(dplan_week3_1);
			var encoded_array_dplan_week3_2 = Ext.encode(dplan_week3_2);
			var encoded_array_dplan_week4_1 = Ext.encode(dplan_week4_1);
			var encoded_array_dplan_week4_2 = Ext.encode(dplan_week4_2);

		}


		Ext.Ajax.request({  
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_master_lesson_plan&m=get_action',
			params: {
				task 				: lessonplan_post2db,
				lesplan_id 			: lesplan_id_create_pk, 
				lesplan_code 		: lesplan_code_create, 
				lesplan_teacher		: lesplan_teacher_create,  
				lesplan_class		: lesplan_class_create, 
				lesplan_theme		: lesplan_theme_create,
				lesplan_subtheme	: lesplan_subtheme_create,
				lesplan_note 		: lesplan_note_create,
				lesplan_month		: lesplan_month_create,
				lesplan_year		: lesplan_year_create,
				lesplan_capacity	: lesplan_capacity_create,

				//Detail Lesson Plan
				dplan_id			: encoded_array_dplan_id, 
				dplan_master		: eval(get_pk_id()),
				dplan_time_start	: encoded_array_dplan_time_start, 
				dplan_time_end		: encoded_array_dplan_time_end, 
				dplan_daily_schedule: encoded_array_dplan_daily_schedule,
				dplan_week1_1 		: encoded_array_dplan_week1_1,
				dplan_week1_2 		: encoded_array_dplan_week1_2,
				dplan_week2_1  		: encoded_array_dplan_week2_1,
				dplan_week2_2 		: encoded_array_dplan_week2_2,
				dplan_week3_1 		: encoded_array_dplan_week3_1,
				dplan_week3_2 		: encoded_array_dplan_week3_2,
				dplan_week4_1 		: encoded_array_dplan_week4_1,
				dplan_week4_2 		: encoded_array_dplan_week4_2

			}, 
			success: function(response){             
								
				var result=eval(response.responseText);
				if(result!==0){
						// detail_lesson_plan_insert(result)
						Ext.MessageBox.alert(lessonplan_post2db+' OK','Lesson Plan Data is already saved');
						master_lesson_plan_DataStore.reload();
						master_lesson_plan_createWindow.hide();
				}else{
						Ext.MessageBox.show({
						   title: 'Warning',
						   msg: 'Lesson Plan Data cannot be saved',
						   buttons: Ext.MessageBox.OK,
						   animEl: 'save',
						   icon: Ext.MessageBox.WARNING
						});
				} 
				
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.show({
					   title: 'Error',
					   msg: 'Cannot connect to Server',
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
				});	
			}                      
		});
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Form is not valid!.',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
 	/* End of Function */
  
  	/* Function for get PK field */
	function get_pk_id(){
		if(lessonplan_post2db=='UPDATE')
			return master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('lesplan_id');
		else 
			return 0;
	}
	/* End of Function  */
	
	/* Reset form before loading */
	function master_lesson_plan_reset_form(){
		lesplan_idField.reset();
		lesplan_idField.setValue(null);
		lesplan_teacherField.reset();
		lesplan_teacherField.setValue(null);
		lesplan_yearField.reset();
		lesplan_yearField.setValue(null);
		lesplan_codeField.reset();
		lesplan_codeField.setValue(null);
		lesplan_classField.reset();
		lesplan_classField.setValue(null);
		lesplan_monthField.reset();
		lesplan_monthField.setValue(null);
		lesplan_capacityField.reset();
		lesplan_capacityField.setValue(null);
		lesplan_themeField.reset();
		lesplan_themeField.setValue(null);
		lesplan_subThemeField.reset();
		lesplan_subThemeField.setValue(null);
		lesplan_noteField.reset();
		lesplan_noteField.setValue(null);
		detail_lesson_plan_DataStoree.load({params : {master_id : -1}});
	}
 	/* End of Function */
  
	/* setValue to EDIT */
	function master_lesson_plan_set_form(){
		lesplan_idField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('lesplan_id'));
		lesplan_codeField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('lesplan_code'));
		lesplan_teacherField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('karyawan_nama'));
		lesplan_classField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('class_name'));
		lesplan_yearField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('lesplan_year'));
		lesplan_monthField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('lesplan_month'));
		lesplan_themeField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('lesplan_theme'));
		lesplan_subThemeField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('lesplan_subtheme'));
		lesplan_noteField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('lesplan_note'));
		lesplan_capacityField.setValue(master_lesson_plan_ListEditorGrid.getSelectionModel().getSelected().get('lesplan_capacity'));

		detail_lesson_plan_DataStoree.load({params : {master_id : get_pk_id() }});
	}
	/* End setValue to EDIT*/
  
	/* Function for Check if the form is valid */
	function is_master_lesson_plan_valid(){
		return (lesplan_teacherField.isValid());
	}
  	/* End of Function */
  
  	/* Function for Displaying  create Window Form */
	function display_form_window(){
		if(!master_lesson_plan_createWindow.isVisible()){
			
			lessonplan_post2db='CREATE';
			msg='created';
			master_lesson_plan_reset_form();
			
			master_lesson_plan_createWindow.show();
		} else {
			master_lesson_plan_createWindow.toFront();
		}
	}
  	/* End of Function */
 
  	/* Function for Delete Confirm */
	function master_lesson_plan_delete(){
		// only one anamnesa is selected here
		if(master_lesson_plan_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Are you sure to delete this data?', master_lesson_plan_delete);
		} else if(master_lesson_plan_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Are you sure to delete all of this data?', master_lesson_plan_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada yang dipilih untuk dihapus',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */
  
	/* Function for Update Confirm */
	function master_lesson_plan_confirm_update(){
		/* only one record is selected here */
		if(master_lesson_plan_ListEditorGrid.selModel.getCount() == 1) {
			
			lessonplan_post2db='UPDATE';
			msg='updated';
			master_lesson_plan_set_form();
			master_lesson_plan_createWindow.show();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'No Data selected',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */
  
  	/* Function for Delete Record */
	function master_lesson_plan_delete(btn){
		if(btn=='yes'){
			var selections = master_lesson_plan_ListEditorGrid.selModel.getSelections();
			var prez = [];
			for(i = 0; i< master_lesson_plan_ListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.lesplan_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({ 
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_master_lesson_plan&m=get_action', 
				params: { task: "DELETE", ids:  encoded_array }, 
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:  // Success : simply reload
							master_lesson_plan_DataStore.reload();
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: 'Could not delete this entire data',
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					var result=response.responseText;
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: 'Cannot connect to Server',
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});	
				}
			});
		}  
	}
  	/* End of Function */
  
	/* Function for Retrieve DataStore */
	master_lesson_plan_DataStore = new Ext.data.Store({
		id: 'master_lesson_plan_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_master_lesson_plan&m=get_action', 
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: lessonplan_pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'lesplan_id'
		},[
			{name: 'lesplan_id', type: 'int', mapping: 'lesplan_id'}, 
			{name: 'lesplan_teacher', type: 'int', mapping: 'lesplan_teacher'}, 
			{name: 'karyawan_nama', type: 'string', mapping: 'karyawan_nama'}, 
			{name: 'karyawan_no', type: 'int', mapping: 'karyawan_no'}, 
			{name: 'lesplan_capacity', type: 'int', mapping: 'lesplan_capacity'}, 
			{name: 'lesplan_theme', type: 'string', mapping: 'lesplan_theme'}, 
			{name: 'lesplan_subtheme', type: 'string', mapping: 'lesplan_subtheme'}, 
			{name: 'lesplan_note', type: 'string', mapping: 'lesplan_note'}, 
			{name: 'lesplan_year', type: 'string', mapping: 'lesplan_year'}, 
			{name: 'lesplan_month', type: 'string', mapping: 'lesplan_month'}, 
			{name: 'lesplan_code', type: 'string', mapping: 'lesplan_code'}, 
			{name: 'class_name', type: 'string', mapping: 'class_name'}, 
			{name: 'class_id', type: 'int', mapping: 'class_id'}, 
			{name: 'lesplan_creator', type: 'string', mapping: 'lesplan_creator'}, 
			{name: 'lesplan_date_create', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'lesplan_date_create'}, 
			{name: 'lesplan_updater', type: 'string', mapping: 'lesplan_updater'}, 
			{name: 'lesplan_date_update', type: 'date', dateFormat: 'Y-m-d', mapping: 'lesplan_date_update'}
		]),
		sortInfo:{field: 'lesplan_id', direction: "DESC"}
	});
	/* End of Function */
    
  	/* Function for Identify of Window Column Model */
	master_lesson_plan_ColumnModel = new Ext.grid.ColumnModel(
		[{
			header: '#',
			readOnly: true,
			dataIndex: 'lesplan_id',
			width: 40,
			renderer: function(value, cell){
				cell.css = "readonlycell"; // Mengambil Value dari Class di dalam CSS 
				return value;
				},
			hidden: true
		},
		{
			header: 'Code Lesson Plan',
			dataIndex: 'lesplan_code',
			width: 150,
			sortable: true,
			readOnly: true
		}, 
		{
			header: 'Theme',
			dataIndex: 'lesplan_theme',
			width: 150,
			sortable: true
		}, 
		{
			header : 'Sub Theme',
			dataIndex : 'lesplan_subtheme',
			width : 150,
			sortable : true
		},
		
		{
			header: 'Month',
			dataIndex: 'lesplan_month',
			width: 150,
			sortable: true,
			readOnly : true,
			renderer: function(value, cell, record){
				//cell.css = "readonlycell";
				if(record.data.lesplan_month=='01'){
					return 'January';
				}else if(record.data.lesplan_month=='02'){
					return 'February';
				}else if(record.data.lesplan_month=='03'){
					return 'March';
				}else if(record.data.lesplan_month=='04'){
					return 'April';
				}else if(record.data.lesplan_month=='05'){
					return 'May';
				}else if(record.data.lesplan_month=='06'){
					return 'June';
				}else if(record.data.lesplan_month=='07'){
					return 'July';
				}else if(record.data.lesplan_month=='08'){
					return 'August';
				}else if(record.data.lesplan_month=='09'){
					return 'September';
				}else if(record.data.lesplan_month=='10'){
					return 'October';
				}else if(record.data.lesplan_month=='11'){
					return 'November';
				}else if(record.data.lesplan_month=='12'){
					return 'December';
				}
				return value;
			}
		}, 
		{
			header: 'Class',
			dataIndex: 'class_name',
			width: 150,
			sortable: true,
			readOnly: true
		}, 
		{
			header : 'Note',
			dataIndex : 'lesplan_note',
			width : 150,
			sortable : true
		},
		/*
		{
			header: 'Capacity',
			dataIndex: 'lesplan_capacity',
			width: 150,
			sortable: true
		}, 
		*/
		{
			header: 'Creator',
			dataIndex: 'lesplan_creator',
			width: 150,
			sortable: true,
			hidden: true,
			readOnly: true
		}, 
		{
			header: 'Date Created',
			dataIndex: 'lesplan_date_create',
			width: 150,
			sortable: true,
			// hidden: true,
			readOnly: true,
			renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
		}, 
		{
			header: 'Last Update by',
			dataIndex: 'lesplan_updater',
			width: 150,
			sortable: true,
			hidden: true,
			readOnly: true
		}, 
		{
			header: 'Last Update on',
			dataIndex: 'lesplan_date_update',
			width: 150,
			sortable: true,
			hidden: true,
			readOnly: true
		}
		]);
	
	master_lesson_plan_ColumnModel.defaultSortable= true;
	/* End of Function */
    
	/* Declare DataStore and  show datagrid list */
	master_lesson_plan_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 'master_lesson_plan_ListEditorGrid',
		el: 'fp_master_lesson_plan',
		title: 'List Lesson Plan',
		autoHeight: true,
		store: master_lesson_plan_DataStore, // DataStore
		cm: master_lesson_plan_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
	  	width: 1200,
		bbar: new Ext.PagingToolbar({
			lessonplan_pageSize: lessonplan_pageS,
			store: master_lesson_plan_DataStore,
			displayInfo: true
		}),
		tbar: [
		<?php if(eregi('C',$this->m_security->get_access_group_by_kode('MENU_LESSONPLAN'))){ ?>
		{
			text: 'Add',
			tooltip: 'Add new record',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: display_form_window
		}, '-',
		<?php } ?>
		<?php if(eregi('U|R',$this->m_security->get_access_group_by_kode('MENU_LESSONPLAN'))){ ?>
		{
			text: 'Edit',
			tooltip: 'Edit selected record',
			iconCls:'icon-update',
			handler: master_lesson_plan_confirm_update   // Confirm before updating
		}, '-',
		<?php } ?>
		<?php if(eregi('D',$this->m_security->get_access_group_by_kode('MENU_LESSONPLAN'))){ ?>
		{
			text: 'Delete',
			tooltip: 'Delete selected record',
			iconCls:'icon-delete',
			handler: master_lesson_plan_delete   // Confirm before deleting
		}, '-',
		<?php } ?>
		/*
		{
			text: 'Adv Search',
			tooltip: 'Advanced Search',
			iconCls:'icon-search',
			handler: display_form_search_window 
		},
		 '-', 
		 */
			new Ext.app.SearchField({
			store: master_lesson_plan_DataStore,
			params: {start: 0, limit: lessonplan_pageS},
			width: 120
		}),'-',{
			text: 'Refresh',
			tooltip: 'Refresh datagrid',
			handler: master_lesson_plan_reset_search,
			iconCls:'icon-refresh'
		},'-',{
			text: 'Export Excel',
			tooltip: 'Export to Excel(.xls) Document',
			iconCls:'icon-xls',
			handler: master_lesson_plan_export_excel
		}, '-',{
			text: 'Print',
			tooltip: 'Print Document',
			iconCls:'icon-print',
			handler: master_lesson_plan_print  
		}
		]
	});
	master_lesson_plan_ListEditorGrid.render();
	/* End of DataStore */
     
	/* Create Context Menu */
	master_lesson_plan_ContextMenu = new Ext.menu.Menu({
		id: 'anamnesa_ListEditorGridContextMenu',
		items: [
		<?php if(eregi('U|R',$this->m_security->get_access_group_by_kode('MENU_LESSONPLAN'))){ ?>
		{ 
			text: 'Edit', tooltip: 'Edit selected record', 
			iconCls:'icon-update',
			handler: master_lesson_plan_editContextMenu 
		},
		<?php } ?>
		<?php if(eregi('D',$this->m_security->get_access_group_by_kode('MENU_LESSONPLAN'))){ ?>
		{ 
			text: 'Delete', 
			tooltip: 'Delete selected record', 
			iconCls:'icon-delete',
			handler: master_lesson_plan_delete 
		},
		<?php } ?>
		'-',
		{ 
			text: 'Print',
			tooltip: 'Print Document',
			iconCls:'icon-print',
			handler: master_lesson_plan_print 
		},
		{ 
			text: 'Export Excel', 
			tooltip: 'Export to Excel(.xls) Document',
			iconCls:'icon-xls',
			handler: master_lesson_plan_export_excel 
		}
		]
	}); 
	/* End of Declaration */
	
	/* Event while selected row via context menu */
	function onmaster_lessonplan_ListEditGridContextMenu(grid, rowIndex, e) {
		e.stopEvent();
		var coords = e.getXY();
		master_lesson_plan_ContextMenu.rowRecord = grid.store.getAt(rowIndex);
		grid.selModel.selectRow(rowIndex);
		master_lesson_plan_SelectedRow=rowIndex;
		master_lesson_plan_ContextMenu.showAt([coords[0], coords[1]]);
  	}
  	/* End of Function */
	
	/* function for editing row via context menu */
	function master_lesson_plan_editContextMenu(){
		master_lesson_plan_ListEditorGrid.startEditing(master_lesson_plan_SelectedRow,1);
  	}
	/* End of Function */
  	
	master_lesson_plan_ListEditorGrid.addListener('rowcontextmenu', onmaster_lessonplan_ListEditGridContextMenu);
	master_lesson_plan_DataStore.load({params: {start: 0, limit: lessonplan_pageS}});	// load DataStore
	master_lesson_plan_ListEditorGrid.on('afteredit', master_lesson_plan_update); // inLine Editing Record
	
	lesplan_teacher_DataStore = new Ext.data.Store({
		id: 'lesplan_teacher_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_master_lesson_plan&m=get_teacher_list',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: lessonplan_pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'karyawan_id'
		},[
			{name: 'karyawan_id', type: 'int', mapping: 'karyawan_id'},
			{name: 'karyawan_no', type: 'string', mapping: 'karyawan_no'},
			{name: 'karyawan_nama', type: 'string', mapping: 'karyawan_nama'},
			{name: 'cust_tgllahir', type: 'date', dateFormat: 'Y-m-d', mapping: 'cust_tgllahir'},
			{name: 'karyawan_kelamin', type: 'string', mapping: 'karyawan_kelamin'},
			{name: 'cust_telprumah', type: 'string', mapping: 'cust_telprumah'}
		]),
		sortInfo:{field: 'karyawan_no', direction: "ASC"}
	});
	
	lesplan_class_DataStore = new Ext.data.Store({
		id: 'lesplan_class_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_master_lesson_plan&m=get_class_list',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: lessonplan_pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'class_id'
		},[
			{name: 'class_id', type: 'int', mapping: 'class_id'},
			{name: 'class_name', type: 'string', mapping: 'class_name'},
			{name: 'class_capacity', type: 'int', mapping: 'class_capacity'},
			{name: 'class_time_start', type: 'time', mapping: 'class_time_start'},
			{name: 'class_time_end', type: 'time', mapping: 'class_time_end'},
			{name: 'class_notes', type: 'string', mapping: 'class_notes'}
		]),
		sortInfo:{field: 'class_name', direction: "ASC"}
	});
	
	var teacher_tpl = new Ext.XTemplate(
        '<tpl for="."><div class="search-item">',
            '<span><b>({karyawan_no}) {karyawan_nama}</b><br /></span>',
			'Jenis Kelamin : {karyawan_kelamin}',
            /*'{cust_alamat} | {cust_telprumah}',*/
        '</div></tpl>'
    );
	
	var class_tpl = new Ext.XTemplate(
        '<tpl for="."><div class="search-item">',
            '<span><b>{class_name}</b><br /></span>',
            'Capacity : {class_capacity}<br>',
            '{class_time_start} - {class_time_end}',
        '</div></tpl>'
    );
	
	/* Identify  lesplan_id Field */
	lesplan_idField= new Ext.form.NumberField({
		id: 'lesplan_idField',
		allowNegatife : false,
		blankText: '0',
		allowBlank: false,
		allowDecimals: false,
		hidden: true,
		readOnly: true,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	
	
	/* Identify  anam_cust Field */
	lesplan_teacherField= new Ext.form.ComboBox({
		id: 'lesplan_teacherField',
		fieldLabel: 'Teacher',
		store: lesplan_teacher_DataStore,
		mode: 'remote',
		displayField:'karyawan_nama',
		valueField: 'karyawan_id',
        typeAhead: false,
        loadingText: 'Searching...',
        lessonplan_pageSize:10,
        hideTrigger:false,
        tpl: teacher_tpl,
        //applyTo: 'search',
        itemSelector: 'div.search-item',
		triggerAction: 'all',
		lazyRender:true,
		listClass: 'x-combo-list-small',
		anchor: '65%'
		// allowBlank: false
	});
	
	/* Identify lesplan_code Field */
	lesplan_codeField= new Ext.form.TextField({
		id: 'lesplan_codeField',
		fieldLabel: 'No. Code',
		maxLength: 500,
		anchor: '65%'
	});

	lesplan_monthField=new Ext.form.ComboBox({
		id:'lesplan_monthField',
		fieldLabel:'Month',
		store:new Ext.data.SimpleStore({
			fields:['value', 'display'],
			data:[['01','January'],['02','February'],['03','March'],['04','April'],['05','May'],['06','June'],['07','July'],['08','August'],['09','September'],['10','October'],['11','November'],['12','December']]
		}),
		mode: 'local',
		displayField: 'display',
		valueField: 'value',
		// value: thismonth,
		width: 125,
		triggerAction: 'all'
	});

	lesplan_yearField=new Ext.form.ComboBox({
		id:'lesplan_yearField',
		fieldLabel:'Year',
		store:new Ext.data.SimpleStore({
			fields:['tahun'],
			data: [['2013'], ['2014'], ['2015'],['2016'],['2017'],['2018']],
		}),
		mode: 'local',
		displayField: 'tahun',
		valueField: 'tahun',
		// value: thisyear,
		width: 125,
		triggerAction: 'all'
	});

	/* Identify lesplan_capacityField Field */
	lesplan_capacityField= new Ext.form.NumberField({
		id: 'lesplan_capacityField',
		fieldLabel: 'Capacity',
		maxLength: 100,
		width : 125
		// anchor: '50%'
	});

	/* Identify  anam_petugas Field */
	lesplan_classField= new Ext.form.ComboBox({
		id: 'lesplan_classField',
		fieldLabel: 'Class',
		store: lesplan_class_DataStore,
		mode: 'remote',
		displayField:'class_name',
		valueField: 'class_id',
        typeAhead: false,
        loadingText: 'Searching...',
        lessonplan_pageSize:10,
        hideTrigger:false,
        tpl: class_tpl,
        //applyTo: 'search',
        itemSelector: 'div.search-item',
		triggerAction: 'all',
		lazyRender:true,
		listClass: 'x-combo-list-small',
		anchor: '65%'
		// allowBlank: false
	});

	/* Identify Time Start Field */
	dlesplan_timestartField= new Ext.form.TimeField({
		id: 'dlesplan_timestartField',
		fieldLabel: 'Time Start',
		minValue : '07:00',
		maxValue : '13:00',
		format : 'H:i',
		increment : 5,
		anchor: '95%'
	});

	/* Identify Time End Field */
	dlesplan_timeendField= new Ext.form.TimeField({
		id: 'dlesplan_timeendField',
		fieldLabel: 'Time End',
		minValue : '07:00',
		maxValue : '13:00',
		format : 'H:i',
		increment : 5,
		anchor: '95%'
	});

	/* Identify  anam_alergi Field */
	lesplan_themeField= new Ext.form.TextField({
		id: 'lesplan_themeField',
		fieldLabel: 'Theme',
		maxLength: 500,
		anchor: '95%'
	});

	/* Identify lesplan_subThemeField Field */
	lesplan_subThemeField= new Ext.form.TextField({
		id: 'lesplan_subThemeField',
		fieldLabel: 'Sub Theme',
		maxLength: 500,
		anchor: '95%'
	});

	/* Identify lesplan_notes Field */
	lesplan_noteField= new Ext.form.TextArea({
		id: 'lesplan_noteField',
		fieldLabel: 'Notes',
		maxLength: 500,
		anchor: '95%'
	});
	
  	/*Fieldset Master*/
	master_lesson_plan_masterGroup = new Ext.form.FieldSet({
		autoHeight: true,
		// collapsible: true,
		layout:'column',
		items:[
			{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [lesplan_codeField, lesplan_teacherField, lesplan_classField, lesplan_monthField, lesplan_yearField /*, lesplan_capacityField*/] 
			}
			,{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [lesplan_themeField, lesplan_subThemeField, lesplan_noteField, lesplan_idField] 
			}
			]
	});
	
		
	/*Detail Declaration */
		
	// Function for json reader of detail
	var detail_lesson_plan_reader=new Ext.data.JsonReader({
		root: 'results',
		totalProperty: 'total',
		id: ''
	},[
		{name: 'dplan_id', type: 'int', mapping: 'dplan_id'}, 
		{name: 'dplan_master', type: 'int', mapping: 'dplan_master'}, 
		{name: 'dplan_time_start', type: 'string', mapping: 'dplan_time_start'}, 
		{name: 'dplan_time_end', type: 'string', mapping: 'dplan_time_end'}, 
		{name: 'dplan_daily_schedule', type: 'string', mapping: 'dplan_daily_schedule'}, 
		{name: 'dplan_week1_1', type: 'string', mapping: 'dplan_week1_1'},
		{name: 'dplan_week1_2', type: 'string', mapping: 'dplan_week1_2'},
		{name: 'dplan_week2_1', type: 'string', mapping: 'dplan_week2_1'},
		{name: 'dplan_week2_2', type: 'string', mapping: 'dplan_week2_2'},
		{name: 'dplan_week3_1', type: 'string', mapping: 'dplan_week3_1'},
		{name: 'dplan_week3_2', type: 'string', mapping: 'dplan_week3_2'},
		{name: 'dplan_week4_1', type: 'string', mapping: 'dplan_week4_1'},
		{name: 'dplan_week4_2', type: 'string', mapping: 'dplan_week4_2'},
	]);
	//eof
	
	//function for json writer of detail
	var detail_lesson_plan_writer = new Ext.data.JsonWriter({
		encode: true,
		writeAllFields: false
	});
	//eof
	
	/* Function for Retrieve DataStore of detail*/
	detail_lesson_plan_DataStoree = new Ext.data.Store({
		id: 'detail_lesson_plan_DataStoree',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_master_lesson_plan&m=detail_lesson_plan_list', 
			method: 'POST'
		}),
		reader: detail_lesson_plan_reader,
		baseParams:{start: 0, limit: lessonplan_pageS},
		sortInfo:{field: 'dplan_id', direction: "ASC"}
	});
	/* End of Function */
	
	//function for editor of detail
	var editor_detail_lesson_plan= new Ext.ux.grid.RowEditor({
        saveText: 'Update'
    });
	//eof
	
	//declaration of detail coloumn model
	detail_lesson_plan_ColumnModel = new Ext.grid.ColumnModel(
		[
		{
			header: 'ID',
			dataIndex: 'dplan_id',
			width: 70,
			sortable: false,
			hidden : true
		},
		{
			header: 'Start',
			dataIndex: 'dplan_time_start',
			width: 70,
			sortable: false,
			// renderer: Ext.util.Format.dateRenderer('H:i'),
			editor: dlesplan_timestartField	
		},
		{
			header: 'End',
			dataIndex: 'dplan_time_end',
			width: 70,
			sortable: false,
			editor : dlesplan_timeendField
		},
		{
			header: 'Daily Schedule',
			dataIndex: 'dplan_daily_schedule',
			width: 115,
			sortable: false,
			editor: new Ext.form.TextArea({
				maxLength: 250
          	})
		},
		{
			header: 'Week 1 - Part 1',
			dataIndex: 'dplan_week1_1',
			width: 115,
			sortable: false,
			editor: new Ext.form.TextArea({
				maxLength: 250
          	})
		},
		{
			header: 'Week 1 - Part 2',
			dataIndex: 'dplan_week1_2',
			width: 115,
			sortable: false,
			editor: new Ext.form.TextArea({
				maxLength: 250
          	})
		},
		{
			header: 'Week 2 - Part 1',
			dataIndex: 'dplan_week2_1',
			width: 115,
			sortable: false,
			editor: new Ext.form.TextArea({
				maxLength: 250
          	})
		},
		{
			header: 'Week 2 - Part 2',
			dataIndex: 'dplan_week2_2',
			width: 115,
			sortable: false,
			editor: new Ext.form.TextArea({
				maxLength: 250
          	})
		},
		{
			header: 'Week 3 - Part 1',
			dataIndex: 'dplan_week3_1',
			width: 115,
			sortable: false,
			editor: new Ext.form.TextArea({
				maxLength: 250
          	})
		},
		{
			header: 'Week 3 - Part 2',
			dataIndex: 'dplan_week3_2',
			width: 115,
			sortable: false,
			editor: new Ext.form.TextArea({
				maxLength: 250
          	})
		},
		{
			header: 'Week 4 - Part 1',
			dataIndex: 'dplan_week4_1',
			width: 115,
			sortable: false,
			editor: new Ext.form.TextArea({
				maxLength: 250
          	})
		},
		{
			header: 'Week 4 - Part 2',
			dataIndex: 'dplan_week4_2',
			width: 115,
			sortable: false,
			editor: new Ext.form.TextArea({
				maxLength: 250
          	})
		}
		]
	);
	detail_lesson_plan_ColumnModel.defaultSortable= true;
	//eof
	
	
	//declaration of detail list editor grid
	detail_lesson_plan_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 'detail_lesson_plan_ListEditorGrid',
		el: 'fp_detail_lesson_plan',
		title: 'Detail Lesson Plan',
		height: 300,
		width: 1200,
		autoScroll: true,
		store: detail_lesson_plan_DataStoree, // DataStore
		colModel: detail_lesson_plan_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		region: 'center',
        margins: '0 5 5 5',
		plugins: [editor_detail_lesson_plan],
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:false},
		<?php if(eregi('U|C',$this->m_security->get_access_group_by_kode('MENU_LESSONPLAN'))){ ?>
		
		tbar: [
		{
			text: 'Add',
			tooltip: 'Add new detail record',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: detail_lesson_add
		}, '-',{
			text: 'Delete',
			tooltip: 'Delete detail selected record',
			iconCls:'icon-delete',
			handler: detail_lesson_confirm_delete
		}
		]
		<?php } ?>
	});
	//eof
	
	
	//function of detail add
	function detail_lesson_add(){
		var edit_detail_lesson= new detail_lesson_plan_ListEditorGrid.store.recordType({
			dplan_id			:'',		
			dplan_time_start	:'',		
			dplan_time_end		:'',		
			dplan_time_schedule	:'',		
			dplan_week1_1		:'',		
			dplan_week1_2		:'',
			dplan_week2_1		:'',	
			dplan_week2_2		:'',	
			dplan_week3_1		:'',	
			dplan_week3_2		:'',	
			dplan_week4_1		:'',	
			dplan_week4_2		:''
		});
		editor_detail_lesson_plan.stopEditing();
		detail_lesson_plan_DataStoree.insert(0, edit_detail_lesson);
		detail_lesson_plan_ListEditorGrid.getView().refresh();
		detail_lesson_plan_ListEditorGrid.getSelectionModel().selectRow(0);
		editor_detail_lesson_plan.startEditing(0);
	}
	
	//function for refresh detail
	function refresh_detail_lesson_plan(){
		detail_lesson_plan_DataStoree.commitChanges();
		detail_lesson_plan_ListEditorGrid.getView().refresh();
	}
	//eof
	
	//function for insert detail
	function detail_lesson_plan_insert(pkid){
		var dplan_id = [];
        var dplan_master = [];
        var dplan_time_start = [];
        var dplan_time_end = [];
        var dplan_daily_schedule = [];
        var dplan_week1_1 = [];
        var dplan_week1_2 = [];
        var dplan_week2_1 = [];
        var dplan_week2_2 = [];
        var dplan_week3_1 = [];
        var dplan_week3_2 = [];
        var dplan_week4_1 = [];
        var dplan_week4_2 = [];
		
        if(detail_lesson_plan_DataStoree.getCount()>0){
            for(i=0; i<detail_lesson_plan_DataStoree.getCount();i++){
                if(detail_lesson_plan_DataStoree.getAt(i).data.dplan_time_start!==""
				   && detail_lesson_plan_DataStoree.getAt(i).data.dplan_time_end!==""){

                  	dplan_id.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_id);
					dplan_time_start.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_time_start);
                   	dplan_time_end.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_time_end);
					dplan_daily_schedule.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_daily_schedule);
					dplan_week1_1.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week1_1);
					dplan_week1_2.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week1_2);
					dplan_week2_1.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week2_1);
					dplan_week2_2.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week2_2);
					dplan_week3_1.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week3_1);
					dplan_week3_2.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week3_2);
					dplan_week4_1.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week4_1);
					dplan_week4_2.push(detail_lesson_plan_DataStoree.getAt(i).data.dplan_week4_2);
                }
            }
			
			var encoded_array_dplan_id = Ext.encode(dplan_id);
			var encoded_array_dplan_time_start = Ext.encode(dplan_time_start);
			var encoded_array_dplan_time_end = Ext.encode(dplan_time_end);
			var encoded_array_dplan_daily_schedule = Ext.encode(dplan_daily_schedule);
			var encoded_array_dplan_week1_1 = Ext.encode(dplan_week1_1);
			var encoded_array_dplan_week1_2 = Ext.encode(dplan_week1_2);
			var encoded_array_dplan_week2_1 = Ext.encode(dplan_week2_1);
			var encoded_array_dplan_week2_2 = Ext.encode(dplan_week2_2);
			var encoded_array_dplan_week3_1 = Ext.encode(dplan_week3_1);
			var encoded_array_dplan_week3_2 = Ext.encode(dplan_week3_2);
			var encoded_array_dplan_week4_1 = Ext.encode(dplan_week4_1);
			var encoded_array_dplan_week4_2 = Ext.encode(dplan_week4_2);
				
			Ext.Ajax.request({
				waitMsg: 'Mohon tunggu...',
				url: 'index.php?c=c_master_lesson_plan&m=detail_detail_lesson_plan_insert',
				params:{
					dplan_id			: encoded_array_dplan_id,
					dplan_master		: pkid, 
					dplan_time_start 	: encoded_array_dplan_time_start,
					dplan_time_end		: encoded_array_dplan_time_end,
					dplan_daily_schedule: encoded_array_dplan_daily_schedule,
					dplan_week1_1		: encoded_array_dplan_week1_1,
					dplan_week1_2		: encoded_array_dplan_week1_2,
					dplan_week2_1		: encoded_array_dplan_week2_1,
					dplan_week2_2		: encoded_array_dplan_week2_2,
					dplan_week3_1		: encoded_array_dplan_week3_1,
					dplan_week3_2		: encoded_array_dplan_week3_2,
					dplan_week4_1		: encoded_array_dplan_week4_1,
					dplan_week4_2		: encoded_array_dplan_week4_2
				},
				success:function(response){
					master_lesson_plan_DataStore.reload()
				},
				failure: function(response){
					Ext.MessageBox.hide();
					var result=response.responseText;
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: 'Tidak bisa terhubung dengan database server',
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});	
				}
			});
					
        }
		
	}
	//eof
	
	
	/* Function for Delete Confirm of detail */
	function detail_lesson_confirm_delete(){
		// only one record is selected here
		if(detail_lesson_plan_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Are you sure to delete this data?', detail_lesson_delete);
		} else if(detail_lesson_plan_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Are you sure to delete all of this data?', detail_lesson_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'No data selected',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	//eof
	
	//function for Delete of detail
	function detail_lesson_delete(btn){
		if(btn=='yes'){
			var s = detail_lesson_plan_ListEditorGrid.getSelectionModel().getSelections();
			for(var i = 0, r; r = s[i]; i++){
				detail_lesson_plan_DataStoree.remove(r);
			}
		}  
	}
	//eof
	
	//event on update of detail data store
	detail_lesson_plan_DataStoree.on('update', refresh_detail_lesson_plan);
	
	/* Function for retrieve create Window Panel*/ 
	master_lesson_plan_createForm = new Ext.FormPanel({
		labelAlign: 'left',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 1200,        
		items: [master_lesson_plan_masterGroup,detail_lesson_plan_ListEditorGrid],
		buttons: [
			<?php if(eregi('U|C',$this->m_security->get_access_group_by_kode('MENU_LESSONPLAN'))){ ?>
			{
				text: 'Save and Close',
				handler: master_lesson_plan_create
			}
			,
			<?php } ?>
			{
				text: 'Cancel',
				handler: function(){
					master_lesson_plan_createWindow.hide();
				}
			}
		]
	});
	/* End  of Function*/
	
	/* Function for retrieve create Window Form */
	master_lesson_plan_createWindow= new Ext.Window({
		id: 'master_lesson_plan_createWindow',
		title: lessonplan_post2db+'Lesson Plan',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		x:0,
		y:0,
		plain:true,
		layout: 'fit',
		modal: true,
		renderTo: 'elwindow_master_lesson_plan_create',
		items: master_lesson_plan_createForm
	});
	/* End Window */
	
	/* Function for action list search */
	function master_lesson_plan_list_search(){
		// render according to a SQL date format.
		var lesplan_id_search=null;
		var anam_cust_search=null;
		var anam_tanggal_search_date="";
		var anam_petugas_search=null;
		var anam_pengobatan_search=null;
		var anam_perawatan_search=null;
		var anam_terapi_search=null;
		var anam_alergi_search=null;
		var anam_obatalergi_search=null;
		var anam_efekobatalergi_search=null;
		var anam_hamil_search=null;
		var anam_kb_search=null;
		var anam_harapan_search=null;

		if(lesplan_idSearchField.getValue()!==null){lesplan_id_search=lesplan_idSearchField.getValue();}
		if(lesplan_teacherSearchField.getValue()!==null){anam_cust_search=lesplan_teacherSearchField.getValue();}
		if(lesplan_tanggalSearchField.getValue()!==""){anam_tanggal_search_date=lesplan_tanggalSearchField.getValue().format('Y-m-d');}
		if(lesplan_classSearchField.getValue()!==null){anam_petugas_search=lesplan_classSearchField.getValue();}
		if(anam_pengobatanSearchField.getValue()!==null){anam_pengobatan_search=anam_pengobatanSearchField.getValue();}
		if(anam_perawatanSearchField.getValue()!==null){anam_perawatan_search=anam_perawatanSearchField.getValue();}
		if(anam_terapiSearchField.getValue()!==null){anam_terapi_search=anam_terapiSearchField.getValue();}
		if(anam_alergiSearchField.getValue()!==null){anam_alergi_search=anam_alergiSearchField.getValue();}
		if(anam_obatalergiSearchField.getValue()!==null){anam_obatalergi_search=anam_obatalergiSearchField.getValue();}
		if(anam_efekobatalergiSearchField.getValue()!==null){anam_efekobatalergi_search=anam_efekobatalergiSearchField.getValue();}
		if(anam_hamilSearchField.getValue()!==null){anam_hamil_search=anam_hamilSearchField.getValue();}
		if(anam_kbSearchField.getValue()!==null){anam_kb_search=anam_kbSearchField.getValue();}
		if(anam_harapanSearchField.getValue()!==null){anam_harapan_search=anam_harapanSearchField.getValue();}
		// change the store parameters
		master_lesson_plan_DataStore.baseParams = {
			task: 'SEARCH',
			lesplan_id	:	lesplan_id_search, 
			anam_cust	:	anam_cust_search, 
			anam_tanggal	:	anam_tanggal_search_date, 
			anam_petugas	:	anam_petugas_search, 
			anam_pengobatan	:	anam_pengobatan_search, 
			anam_perawatan	:	anam_perawatan_search, 
			anam_terapi	:	anam_terapi_search, 
			anam_alergi	:	anam_alergi_search, 
			anam_obatalergi	:	anam_obatalergi_search, 
			anam_efekobatalergi	:	anam_efekobatalergi_search, 
			anam_hamil	:	anam_hamil_search, 
			anam_kb	:	anam_kb_search, 
			anam_harapan	:	anam_harapan_search
		};
		// Cause the datastore to do another query : 
		master_lesson_plan_DataStore.reload({params: {start: 0, limit: lessonplan_pageS}});
	}
		
	/* Function for reset search result */
	function master_lesson_plan_reset_search(){
		// reset the store parameters
		master_lesson_plan_DataStore.baseParams = { task: 'LIST', start: 0, limit: lessonplan_pageS };
		master_lesson_plan_DataStore.reload({params: {start: 0, limit: lessonplan_pageS}});
		master_lesson_plan_searchWindow.close();
	};
	/* End of Fuction */
	
	/* Field for search */
	/* Identify  lesplan_id Search Field */
	lesplan_idSearchField= new Ext.form.NumberField({
		id: 'lesplan_idSearchField',
		fieldLabel: 'Anam Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	
	});
	/* Identify  anam_cust Search Field */
	lesplan_teacherSearchField= new Ext.form.ComboBox({
		id: 'lesplan_teacherSearchField',
		fieldLabel : 'Teacher',
		store: lesplan_teacher_DataStore,
		mode: 'remote',
		displayField:'karyawan_nama',
		valueField: 'karyawan_id',
        typeAhead: false,
        loadingText: 'Searching...',
        lessonplan_pageSize:10,
        hideTrigger:false,
        tpl: teacher_tpl,
        //applyTo: 'search',
        itemSelector: 'div.search-item',
		triggerAction: 'all',
		lazyRender:true,
		listClass: 'x-combo-list-small',
		anchor: '95%'
	
	});
	/* Identify Tanggal Search Field */
	lesplan_tanggalSearchField= new Ext.form.DateField({
		id: 'lesplan_tanggalSearchField',
		fieldLabel: 'Tanggal',
		format : 'Y-m-d'
	
	});
	/* Identify  anam_petugas Search Field */
	lesplan_classSearchField= new Ext.form.ComboBox({
		id: 'lesplan_classSearchField',
		fieldLabel: 'Class',
		store: lesplan_class_DataStore,
		mode: 'remote',
		displayField:'class_name',
		valueField: 'class_id',
        typeAhead: false,
        loadingText: 'Searching...',
        lessonplan_pageSize:10,
        hideTrigger:false,
        tpl: class_tpl,
        //applyTo: 'search',
        itemSelector: 'div.search-item',
		triggerAction: 'all',
		lazyRender:true,
		listClass: 'x-combo-list-small',
		anchor: '95%'
	
	});
    
	/* Function for retrieve search Form Panel */
	master_lesson_plan_searchForm = new Ext.FormPanel({
		labelAlign: 'left',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 600,        
		items: [{
			layout:'column',
			border:false,
			items:[
			{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [ lesplan_classSearchField] 
			}
 
			,{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [] 
			}
			]
		}]
		,
		buttons: [{
				text: 'Search',
				handler: master_lesson_plan_list_search
			},{
				text: 'Close',
				handler: function(){
					master_lesson_plan_searchWindow.hide();
				}
			}
		]
	});
    /* End of Function */ 
	 
	/* Function for retrieve search Window Form, used for andvaced search */
	master_lesson_plan_searchWindow = new Ext.Window({
		title: 'Searching Lesson Plan',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		plain:true,
		layout: 'fit',
		x: 0,
		y: 0,
		modal: true,
		renderTo: 'elwindow_lesson_plan_search',
		items: master_lesson_plan_searchForm
	});
    /* End of Function */ 
	 
  	/* Function for Displaying  Search Window Form */
	function display_form_search_window(){
		if(!master_lesson_plan_searchWindow.isVisible()){
			master_lesson_plan_searchWindow.show();
		} else {
			master_lesson_plan_searchWindow.toFront();
		}
	}
  	/* End Function */
	
	/* Function for print List Grid */
	function master_lesson_plan_print(){
		var searchquery = "";
		var anam_cust_print=null;
		var anam_tanggal_print_date="";
		var anam_petugas_print=null;
		var anam_pengobatan_print=null;
		var anam_perawatan_print=null;
		var anam_terapi_print=null;
		var anam_alergi_print=null;
		var anam_obatalergi_print=null;
		var anam_efekobatalergi_print=null;
		var anam_hamil_print=null;
		var anam_kb_print=null;
		var anam_harapan_print=null;
		var win;              
		// check if we do have some search data...
		if(master_lesson_plan_DataStore.baseParams.query!==null){searchquery = master_lesson_plan_DataStore.baseParams.query;}
		if(master_lesson_plan_DataStore.baseParams.anam_cust!==null){anam_cust_print = master_lesson_plan_DataStore.baseParams.anam_cust;}
		if(master_lesson_plan_DataStore.baseParams.anam_tanggal!==""){anam_tanggal_print_date = master_lesson_plan_DataStore.baseParams.anam_tanggal;}
		if(master_lesson_plan_DataStore.baseParams.anam_petugas!==null){anam_petugas_print = master_lesson_plan_DataStore.baseParams.anam_petugas;}
		if(master_lesson_plan_DataStore.baseParams.anam_pengobatan!==null){anam_pengobatan_print = master_lesson_plan_DataStore.baseParams.anam_pengobatan;}
		if(master_lesson_plan_DataStore.baseParams.anam_perawatan!==null){anam_perawatan_print = master_lesson_plan_DataStore.baseParams.anam_perawatan;}
		if(master_lesson_plan_DataStore.baseParams.anam_terapi!==null){anam_terapi_print = master_lesson_plan_DataStore.baseParams.anam_terapi;}
		if(master_lesson_plan_DataStore.baseParams.anam_alergi!==null){anam_alergi_print = master_lesson_plan_DataStore.baseParams.anam_alergi;}
		if(master_lesson_plan_DataStore.baseParams.anam_obatalergi!==null){anam_obatalergi_print = master_lesson_plan_DataStore.baseParams.anam_obatalergi;}
		if(master_lesson_plan_DataStore.baseParams.anam_efekobatalergi!==null){anam_efekobatalergi_print = master_lesson_plan_DataStore.baseParams.anam_efekobatalergi;}
		if(master_lesson_plan_DataStore.baseParams.anam_hamil!==null){anam_hamil_print = master_lesson_plan_DataStore.baseParams.anam_hamil;}
		if(master_lesson_plan_DataStore.baseParams.anam_kb!==null){anam_kb_print = master_lesson_plan_DataStore.baseParams.anam_kb;}
		if(master_lesson_plan_DataStore.baseParams.anam_harapan!==null){anam_harapan_print = master_lesson_plan_DataStore.baseParams.anam_harapan;}

		Ext.Ajax.request({   
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_master_lesson_plan&m=get_action',
		params: {
			task: "PRINT",
		  	query: searchquery,                    		
			anam_cust : anam_cust_print,
		  	anam_tanggal : anam_tanggal_print_date, 
			anam_petugas : anam_petugas_print,
			anam_pengobatan : anam_pengobatan_print,
			anam_perawatan : anam_perawatan_print,
			anam_terapi : anam_terapi_print,
			anam_alergi : anam_alergi_print,
			anam_obatalergi : anam_obatalergi_print,
			anam_efekobatalergi : anam_efekobatalergi_print,
			anam_hamil : anam_hamil_print,
			anam_kb : anam_kb_print,
			anam_harapan : anam_harapan_print,
		  	currentlisting: master_lesson_plan_DataStore.baseParams.task // this tells us if we are searching or not
		}, 
		success: function(response){              
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				win = window.open('./anamnesalist.html','anamnesalist','height=400,width=600,resizable=1,scrollbars=1, menubar=1');
				
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: 'Cannot print the data!',
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}  
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: 'Cannot connect to Server',
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});		
		} 	                     
		});
	}
	/* Enf Function */
	
	/* Function for print Export to Excel Grid */
	function master_lesson_plan_export_excel(){
		var searchquery = "";
		var anam_cust_2excel=null;
		var anam_tanggal_2excel_date="";
		var anam_petugas_2excel=null;
		var anam_pengobatan_2excel=null;
		var anam_perawatan_2excel=null;
		var anam_terapi_2excel=null;
		var anam_alergi_2excel=null;
		var anam_obatalergi_2excel=null;
		var anam_efekobatalergi_2excel=null;
		var anam_hamil_2excel=null;
		var anam_kb_2excel=null;
		var anam_harapan_2excel=null;
		var win;              
		// check if we do have some search data...
		if(master_lesson_plan_DataStore.baseParams.query!==null){searchquery = master_lesson_plan_DataStore.baseParams.query;}
		if(master_lesson_plan_DataStore.baseParams.anam_cust!==null){anam_cust_2excel = master_lesson_plan_DataStore.baseParams.anam_cust;}
		if(master_lesson_plan_DataStore.baseParams.anam_tanggal!==""){anam_tanggal_2excel_date = master_lesson_plan_DataStore.baseParams.anam_tanggal;}
		if(master_lesson_plan_DataStore.baseParams.anam_petugas!==null){anam_petugas_2excel = master_lesson_plan_DataStore.baseParams.anam_petugas;}
		if(master_lesson_plan_DataStore.baseParams.anam_pengobatan!==null){anam_pengobatan_2excel = master_lesson_plan_DataStore.baseParams.anam_pengobatan;}
		if(master_lesson_plan_DataStore.baseParams.anam_perawatan!==null){anam_perawatan_2excel = master_lesson_plan_DataStore.baseParams.anam_perawatan;}
		if(master_lesson_plan_DataStore.baseParams.anam_terapi!==null){anam_terapi_2excel = master_lesson_plan_DataStore.baseParams.anam_terapi;}
		if(master_lesson_plan_DataStore.baseParams.anam_alergi!==null){anam_alergi_2excel = master_lesson_plan_DataStore.baseParams.anam_alergi;}
		if(master_lesson_plan_DataStore.baseParams.anam_obatalergi!==null){anam_obatalergi_2excel = master_lesson_plan_DataStore.baseParams.anam_obatalergi;}
		if(master_lesson_plan_DataStore.baseParams.anam_efekobatalergi!==null){anam_efekobatalergi_2excel = master_lesson_plan_DataStore.baseParams.anam_efekobatalergi;}
		if(master_lesson_plan_DataStore.baseParams.anam_hamil!==null){anam_hamil_2excel = master_lesson_plan_DataStore.baseParams.anam_hamil;}
		if(master_lesson_plan_DataStore.baseParams.anam_kb!==null){anam_kb_2excel = master_lesson_plan_DataStore.baseParams.anam_kb;}
		if(master_lesson_plan_DataStore.baseParams.anam_harapan!==null){anam_harapan_2excel = master_lesson_plan_DataStore.baseParams.anam_harapan;}

		Ext.Ajax.request({   
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_master_lesson_plan&m=get_action',
		params: {
			task: "EXCEL",
		  	query: searchquery,                    		
			anam_cust : anam_cust_2excel,
		  	anam_tanggal : anam_tanggal_2excel_date, 
			anam_petugas : anam_petugas_2excel,
			anam_pengobatan : anam_pengobatan_2excel,
			anam_perawatan : anam_perawatan_2excel,
			anam_terapi : anam_terapi_2excel,
			anam_alergi : anam_alergi_2excel,
			anam_obatalergi : anam_obatalergi_2excel,
			anam_efekobatalergi : anam_efekobatalergi_2excel,
			anam_hamil : anam_hamil_2excel,
			anam_kb : anam_kb_2excel,
			anam_harapan : anam_harapan_2excel,
		  	currentlisting: master_lesson_plan_DataStore.baseParams.task // this tells us if we are searching or not
		},
		success: function(response){              
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				win = window.location=('./export2excel.php');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: 'Cannot export to excel now!',
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}  
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: 'Cannot connect to Server',
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});    
		} 	                     
		});
	}
	/*End of Function */
	
});
	</script>
<body>
<div>
	<div class="col">
        <div id="fp_master_lesson_plan"></div>
         <div id="fp_detail_lesson_plan"></div>
		<div id="elwindow_master_lesson_plan_create"></div>
        <div id="elwindow_lesson_plan_search"></div>
    </div>
</div>
</body>